var e = require("../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../@babel/runtime/regenerator")), t = require("../../../@babel/runtime/helpers/asyncToGenerator"), a = getApp();

Page({
    data: {
        questionFlag: !1,
        posterFlag: !1,
        recommend_tips: "",
        resultData: {},
        poster_url: "",
        member_id: "",
        health_id: 0
    },
    onLoad: function(e) {
        console.log(e);
        var t = 0;
        if (e.member_id && "" != e.member_id) t = e.member_id; else try {
            t = wx.getStorageSync("yz_uid");
        } catch (e) {
            console.log(e);
        }
        this.data.member_id = t;
        var a = decodeURIComponent(e.scene);
        if (a) {
            var o = [];
            o = a.split(",");
            for (var s = 0; s < o.length; s++) {
                var n;
                n = o[s].split("="), console.log(n), "member_id" == n[0] && (this.data.member_id = n[1]);
            }
            console.log(o);
        }
        this.getResultData();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {
        return {
            path: "/packageE/healthy/healthyResult/healthyResult?member_id=" + this.data.member_id
        };
    },
    getResultData: function() {
        var e = this, t = a.getNetAddresss("plugin.health-assessment.api.index.getData"), o = this.data.member_id;
        console.log(o), a._postNetWork({
            url: t,
            data: {
                member_id: o,
                art: "getResult"
            },
            success: function(t) {
                var a = t.data;
                if (1 == a.result) {
                    var o = a.data.getResult;
                    console.log("成功", o), e.getPoste(o.record_id, o.health_id), 1 == o.is_healthy && e.setData({
                        health_id: o.health_id,
                        recommend_tips: o.recommend_tips,
                        questionFlag: !0
                    }), e.setData({
                        resultData: o
                    });
                }
            },
            fail: function(e) {
                console.log(e.msg);
            }
        });
    },
    setQuestionFlag: function() {
        this.setData({
            questionFlag: !this.data.questionFlag
        });
    },
    setPosterFlag: function() {
        this.setData({
            posterFlag: !this.data.posterFlag
        });
    },
    resetHealthy: function() {
        var e = this.data.health_id;
        e < 1 || wx.redirectTo({
            url: "/packageE/healthy/healthyPaper/healthyPaper?health_id=" + e
        });
    },
    getPoste: function(e, t) {
        var o = this, s = a.getNetAddresss("plugin.health-assessment.api.index.getData");
        a._postNetWork({
            url: s,
            data: {
                art: "getPoster",
                health_type: "2",
                record_id: e,
                health_id: t
            },
            success: function(e) {
                var t = e.data;
                1 == t.result && o.setData({
                    poster_url: t.data.getPoster.url_path
                });
            },
            fail: function(e) {
                console.log(e.msg);
            }
        });
    },
    checkWritePotosAlbum: function() {
        var a = this;
        return t(e.default.mark(function t() {
            var o;
            return e.default.wrap(function(e) {
                for (;;) switch (e.prev = e.next) {
                  case 0:
                    return o = a, e.next = 3, a.getAuthSetting("scope.writePhotosAlbum");

                  case 3:
                    if (e.sent) {
                        e.next = 7;
                        break;
                    }
                    return wx.showModal({
                        title: "请开启授权",
                        content: "是否跳转设置页开启授权",
                        success: function(e) {
                            e.confirm ? wx.openSetting({
                                success: function(e) {
                                    e.authSetting["scope.writePhotosAlbum"] ? o.saveImg() : console.log("还是没授权");
                                }
                            }) : e.cancel && console.log("用户点击取消");
                        }
                    }), e.abrupt("return");

                  case 7:
                    a.saveImg();

                  case 8:
                  case "end":
                    return e.stop();
                }
            }, t);
        }))();
    },
    saveImg: function() {
        var e = this;
        console.log("执行");
        var t = this.data.poster_url;
        wx.downloadFile({
            url: t,
            success: function(t) {
                console.log(t), wx.saveImageToPhotosAlbum({
                    filePath: t.tempFilePath,
                    success: function(t) {
                        wx.showToast({
                            title: "保存成功",
                            icon: "none",
                            duration: 2e3
                        }), e.setPosterFlag();
                    },
                    fail: function(e) {
                        console.log(e);
                    }
                });
            }
        });
    },
    getAuthSetting: function(e) {
        return new Promise(function(t, a) {
            wx.getSetting({
                success: function(a) {
                    a.authSetting[e] ? t(!0) : wx.authorize({
                        scope: e,
                        success: function() {
                            t(!0);
                        },
                        fail: function() {
                            t(!1);
                        }
                    });
                },
                fail: function() {
                    t(!1);
                }
            });
        });
    }
});